package com.graduation.project.utils;

import com.graduation.project.enums.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 卑微小峰
 * @date 2022/9/24
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultUtil<T> {
    private  int code;
    private  String msg ;
    private  T data;

    public ResultUtil(int code) {
        this.code = code;
        this.msg = "";
        this.data = null;
    }

    public ResultUtil(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public static ResultUtil<?> Success(int code, String msg, Object data) {
        return new ResultUtil(code, msg, data);
    }
    public static ResultUtil<?> Success(int code, String msg) {
        return Success(code, msg, null);
    }
    public static ResultUtil<?> Success(ResultCodeEnum resultCodeEnum) {
        return Success(resultCodeEnum.getCode(), resultCodeEnum.getMsg(), null);
    }
    public static ResultUtil<?> Success(ResultCodeEnum resultCodeEnum, Object data) {
        return Success(resultCodeEnum.getCode(), resultCodeEnum.getMsg(), data);
    }

    public static ResultUtil<?> Failed(int code, String msg, Object data) {
        return new ResultUtil(code, msg, data);
    }
    public static ResultUtil<?> Failed(int code, String msg) {
        return Failed(code, msg, null);
    }
    public static ResultUtil<?> Failed(ResultCodeEnum resultCodeEnum) {
        return Failed(resultCodeEnum.getCode(), resultCodeEnum.getMsg(), null);
    }
    public static ResultUtil<?> Failed(ResultCodeEnum resultCodeEnum, Object data) {
        return Failed(resultCodeEnum.getCode(), resultCodeEnum.getMsg(), data);
    }
}
